Plotly (link here) is one of the two ways we will discuss to make interactive graphs. You can embed them in the application “Dash” to make dashboards, but also you can also just make your reports dynamic.

also, you’ll notice that this github is setup with a special new ability - This is a website now too, displaying the html of the report!

Penguin Plot

First, we make the plot, by saving the ggplot as an object.

library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.4.0      ✔ purrr   0.3.5 
## ✔ tibble  3.1.8      ✔ dplyr   1.0.10
## ✔ tidyr   1.2.1      ✔ stringr 1.5.0 
## ✔ readr   2.1.3      ✔ forcats 0.5.2 
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
library(palmerpenguins)

p <- ggplot(penguins, aes(x = bill_length_mm, y = bill_depth_mm, col = species)) + geom_point()
p
## Warning: Removed 2 rows containing missing values (`geom_point()`).

Penguin Plotly

Then, all we need to do is to use the function ggplotly()!

library(plotly)
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
ggplotly(p)